package infiews.crawler;

import infiews.crawler.exceptions.CrawlerException;

import java.io.IOException;
import java.util.HashMap;
import java.util.Properties;

public class Config extends HashMap<Object, Object> {

	public Config() throws CrawlerException{
        super();
        try{
            Properties prop = new Properties();
            prop.load(Config.class.getClassLoader().getResourceAsStream("global.properties"));
            this.putAll(prop);
        }catch(IOException e){
            throw new CrawlerException("Unable to load config file global.properties");
        }
	}
	
	protected Object getValue(String key){
        if(this.containsKey(key)){
            return this.get(key);
        }else{
            return null;
        }
	}

	public Boolean getBoolean( String key ){
        String value = this.getString(key);
		return value != null && Boolean.parseBoolean(value);
	}
	
	public String getString(String key){
        Object value = this.getValue(key);
        if(value != null){
            return (String) value;
        }else{
            return null;
        }
	}
	
	public int getInt(String key){
		String value = this.getString(key);
        if(value == null){
            return 0;
        }
		return Integer.parseInt(value);
	}
	
	private static final long serialVersionUID = 1L;
}
